import { get_life_data } from "@/api/life.js"
import { check_token } from "@/api/user.js"
import { user_Store } from "@/store/user"
const index_router = [
    {
        path: '/',
        name: 'index',
        redirect: () => {
            return { name: 'index_' }
        },
    },
    {
        path: '/index',
        meta: { login: false, requiresAuth: false },
        name: 'index_',
        component: () => import("/src/components/index.vue"),
        beforeEnter: async (to, from, next) => { 
                let user = user_Store()
                if ((user.get_user()?.id!=undefined ) && !user.get_user_life_data()) {
                    user.set_user_life_data(await get_life_data(user.get_user().id, 1))
                } 
            next()
        }
    }
    ,
    {
        path: '/about-this',
        name: 'aboutthis',
        component: () => import("/src/components/aboutthis.vue"),
    }
    ,

    {
        path: '/aboutlife',
        meta: {requiresAuth:true},
        component: () => import("/src/components/life/life_layout.vue"),
        name: 'life',
        redirect: () => {
            //重定向到文本
            return { name: 'life_text' }
        },
        children: [
            { path: 'text', component: () => import("/src/components/life/text/text.vue"), name: 'life_text' },
            { path: 'text_life', component: () => import("/src/components/life/text/life.vue"), name: 'text_life' },
            { path: 'text_food', component: () => import("/src/components/life/text/food.vue"), name: 'text_food' },
            { path: 'text_default', component: () => import("/src/components/life/text/default.vue"), name: 'text_default' },
            { path: 'text_diary', component: () => import("/src/components/life/text/diary.vue"), name: 'text_diary' }
            ,
            { path: 'anaysis', component: () => import("/src/components/life/anaysis.vue"), name: 'anaysis_self' },
            {
                path: 'memory', component: () => import("/src/components/life/memory.vue"), name: 'memory_self',
            }]
    },
    {
        path: '/functions',
        children: [
            {
                path: 'music_play', component: () => import("/src/components/function/music/render_music_play.vue"), name: 'music_play', meta: '1'
            },
            {
                path: 'music', component: () => import("/src/components/function/music/music-layout.vue"), name: 'music',
                redirect: '/functions/music/index/index',
                children: [{
                    path: 'index', component: () => import("/src/components/function/music/index-layout.vue"),
                    children: [{ path: 'index', component: () => import("/src/components/function/music/index/index.vue") },
                    {
                        path: 'singer', component: () => import("/src/components/function/music/index/singer.vue"),
                        redirect: '/functions/music/index/singer/all/all/all/all',
                        children: [{ path: ':name/:area/:sex/:kind', component: () => import("/src/components/function/music/index/render_singers.vue") }]
                    },
                    {
                        path: 'rank', component: () => import("/src/components/function/music/index/rank.vue")
                        ,
                        redirect: '/functions/music/index/rank/1_1',
                        children: [
                            { path: ':select', component: () => import("/src/components/function/music/index/render_rank.vue") }
                        ]
                    },
                    { path: 'playlist', component: () => import("/src/components/function/music/index/playlist.vue") },
                    { path: 'radar', component: () => import("/src/components/function/music/index/radar.vue") },
                    { path: 'mv', component: () => import("/src/components/function/music/index/mv.vue") }
                    ],
                },
                {
                    path: 'me', component: () => import("/src/components/function/music/myself/me-layout.vue"),
                },
                {
                    path: 'rec', component: () => import("/src/components/function/music/rec/rec-layout.vue"),
                },
                {
                    path: 'search', component: () => import("/src/components/function/music/search-box/search.vue")
                },
                
                ]
            },
            { path: 'video', component: () => import("/src/components/function/video/video-layout.vue"), name: 'video' },
            { path: 'tiktok', component: () => import("/src/components/function/tiktok/tiktok-layout.vue"), name: 'tiktok' },
            { path: 'ai', component: () => import("/src/components/function/ai/ai-layout.vue"), name: 'qianfan' },
            
        ]
    },
     {
        path: '/community',
        name: 'community',
        component: () => import("/src/components/community/index.vue"),
    }, {
        path: '/register_retrieve',
        name: 'register_retrieve',
        component: () => import("/src/components/register_retrieve.vue"),
        meta: { requiresAuth: false }
    }
]
export default index_router
